package com.mobilebsc.httpclient.callback;

import java.util.List;

import android.util.Log;

import com.loopj.android.http.RequestParams;
import com.mobilebsc.datatype.Perspective;
import com.mobilebsc.exception.NotImplementedException;

public class PerspectiveRestClientUsage implements
		IRestClientUsage<Perspective>,
		IAsyncTaskCompleteListener<List<Perspective>> {

	private static final String TAG = "PerspectiveRestClientUsage";
	private IAsyncTaskCompleteListener<List<Perspective>> callback;
	private String svcUrl;

	public PerspectiveRestClientUsage(
			IAsyncTaskCompleteListener<List<Perspective>> callback) {
		this.callback = callback;
		this.svcUrl = "perspectives";
	}

	@Override
	public void getAll() {
		PerspectiveHttpResponseHandler httpResponseHandler = new PerspectiveHttpResponseHandler(
				this);
		MbscRestClient.get(svcUrl, null, httpResponseHandler);
	}

	@Override
	public void getById(int perspectiveId) {
		PerspectiveHttpResponseHandler httpResponseHandler = new PerspectiveHttpResponseHandler(
				this);
		MbscRestClient.get(svcUrl, new RequestParams("id", perspectiveId), httpResponseHandler);
	}

	@Override
	public void add(Perspective element) {
		throw new NotImplementedException();
		
	}

	@Override
	public void delete(Perspective element) {
		throw new NotImplementedException();
		
	}
	
	@Override
	public void onTaskComplete(List<Perspective> result) {
		Log.i(TAG, "result[0].content: " + result.get(0).getId() + ", "
				+ result.get(0).getName() + ", "
				+ result.get(0).getDescription());

		callback.onTaskComplete(result);
	}
}